package com.example.demo;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/demo2")
@Controller
public class Demo2 {

    @RequestMapping("/r1")
    public String r1() {
        return "/index.html";
    }

    @RequestMapping("/r2")
    @ResponseBody
    public String r2() {
        return "前端需要的数据";
    }

    @ResponseBody
    @RequestMapping("/r3")
    public String r3() {
        return "<h1>前端需要的数据<h1>";
    }

    @ResponseBody
    @RequestMapping(value = "/r4", produces = "test/plain")
    public String r4() {
        return "<h1>前端需要的数据<h1>";
    }

    @ResponseBody
    @RequestMapping("/r5")
    public UserInfo r5() {
        UserInfo userInfo = new UserInfo("zhangsan", 1, 1);
        return userInfo;
    }

    @ResponseBody
    @RequestMapping("/r6")
    public UserInfo r6(HttpServletResponse response) {
        response.setStatus(404);
        UserInfo userInfo = new UserInfo("zhangsan", 1, 1);
        return userInfo;

    }

    @ResponseBody
    @RequestMapping("/r7")
    public String r7(HttpServletResponse response) {
        response.setHeader("Myhead", "Myhead");
        return "设置成功";
    }

    
}
